//
//  CarpoolWithFriendsAdapter.h
//  CarpoolWithFriends
//
//  Created by Yang Lu on 4/27/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"

enum REQUEST_TYPE {GET,POST,PUT,DELETE};
enum SYNC_MODE {SYNCHRONOUS, ASYNCHRONOUS};

@interface CarpoolWithFriendsAdapter : NSObject
{
    
}

/* Generic function called by all the concrete API call
    @parameter reqType http method: GET, POST, PUT, DELETE
    @parameter syncMode synchronous or asynchronous
    @parameter apiNameStr API name for different modules as URL address
    @parameter sendData query string (used for GET) or json data (used for POST)
    @return NSSTRING* "FAILED" for failure; json data if success
 */
+(NSString*)generalRequest:(enum REQUEST_TYPE)reqType syncMode:(enum SYNC_MODE)syncMode apiName:(NSString*)apiNameStr sendData:(NSObject*)sendData;

/*
 *  Form request. It uses ASIFormDataRequest to send form data.
 *  @parameter reqType http method: GET, POST, PUT, DELETE
 *  @parameter apiNameStr API name for different modules as URL address
 *  @parameer dataPath the path of image under the main bundle
 *  @parameter sendData image data
 *  @parameter postData additional json data
 *  @parameter imageKey the key for the image, so server can retrieve image by request.FILES[imageKey]
 *
 *  @return NSString* "FAILED" for failure; json data if success
 */
+(NSString*)formRequest:(enum SYNC_MODE)syncMode apiName:(NSString*)apiNameStr dataPath:(NSString*)dataPath sendData:(NSData*)sendData postData:(NSObject*)postData imageKey:(NSString*)imageKey;

/////////////////////////////////
//  Account Module
/////////////////////////////////

/* POST account/register
 @parameter email, password, firstname, lastname, phone
 @return BOOL    YES, if successfully register, otherwise NO
 */
+(BOOL)requestRegisterWithEmail: (NSString*)email password:(NSString*)password firstName:(NSString*)firstName lastName:(NSString*)lastName phone:(NSString*)phone retData:(NSMutableDictionary**)retJSON;

/*  POST account/login
    @parameter email, password
    @return BOOL    YES, if successfully login, otherwise NO
*/
+(BOOL)requestLoginWithEmail:(NSString*)email password:(NSString*)password retData:(NSMutableDictionary**)retJSON;

/* POST account/logout
    @parameter userId
    @return
 */
+(BOOL)requestLogoutWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/*  GET account/profile
    @parameter userId
    @return
 */
+(BOOL)requestProfileWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/*  POST account/update_profile
    @parameter userId, fields
    @return
 */
+(BOOL)requestUpdateProfileWithUserId:(NSString*)userId field:(NSDictionary*)fields retData:(NSMutableDictionary**)retJSON;

/*  POST account/update_profile_image
    @parameter userId, image(image file path)
    @return
 */
+(BOOL)requestUpdateProfileImageWithUserId:(NSString*)userId photo:(NSString*)image retData:(NSMutableDictionary**)retJSON;


//////////////////////////////////
//  Friendships Module
//////////////////////////////////

/*  GET friendship/friends
    @parameter  userId
    @return
 */
+(BOOL)requestAllFriendsWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/* POST friendship/request
    @paramter userId
    @return
 */
+(BOOL)sendFriendshipRequestFromRequestor:(NSString*)requestorId requestee:(NSString*)requsteeId retData:(NSMutableDictionary**)retJSON;

/*  POST friendship/deny
    @parameter
    @return
 */
+(BOOL)denyFriendshipRequestFromRequestor:(NSString*)requestorId requestee:(NSString*)requesteeId retData:(NSMutableDictionary**)retJSON;

/*  DELETE friendship/unfriend
    @parameter
    @return
 */
+(BOOL)destroyFriendshipBetweenUserOne:(NSString*)userOneId userTwo:(NSString*)userTwoId retData:(NSMutableDictionary**)retJSON;



//////////////////////////////////
//  Stream
//////////////////////////////////

/* GET stream/popular
    @parameter  userId
    @return 
 */
+(BOOL)requestPopularStreamWithUserId:(NSString *)userId retData:(NSMutableDictionary **)retJSON;

/* GET stream/friends
    @parameter userId
    @return
 */
+(BOOL)requestAllFriendsStreamWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/*  GET stream/person
    @parameter userId
    @return 
 */
+(BOOL)requestStreamWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

+(BOOL)searchFeedWithParameter:(NSDictionary*)parameters retData:(NSMutableDictionary**)retJSON;



//////////////////////////////////
//  Ride Module
//////////////////////////////////
+(BOOL)createRideWithFields:(NSDictionary*)fields retData:(NSMutableDictionary**)retJSON;

+(BOOL)deleteRideWithId:(NSString*)rideId retData:(NSMutableDictionary**)retJSON;

+(BOOL)reserveRideWithId:(NSString*)rideId retData:(NSMutableDictionary**)retJSON;

+(BOOL)inviteUserForRideWithRideId:(NSString*)rideId userId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

+(BOOL)denyRideInvitationWithRideId:(NSString*)rideId invitor:(NSString*)invitorId invitee:(NSString*)inviteeId retData:(NSMutableDictionary**)retJSON;

+(BOOL)denyRideReservationWithRideId:(NSString*)rideId reserver:(NSString*)userId owner:(NSString*)ownerId retData:(NSMutableDictionary**)retJSON;


//////////////////////////////////
//  Message Module
//////////////////////////////////

/* GET message/inbox
    @parameter  userId
    @return
 */
+(BOOL)requestAllInboxMessagesWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/*  GET message/outbox
    @parameter  userId
    @return
 */
+(BOOL)requestAllOutboxMessagesWithUserId:(NSString*)userId retData:(NSMutableDictionary**)retJSON;

/*  POST message/send
    @parameter  
 */
+(BOOL)sendMessageFromUserId:(NSString*)userId toUserId:(NSString*)userId content:(NSString*)content retData:(NSMutableDictionary**)retJSON;

/*  DELETE message/delete
    @parameter  messageId
    @return
 */
+(BOOL)deleteMessageWithMessageId:(NSString*)messageId retData:(NSMutableDictionary**)retJSON;


//for asychronized invoking
//-(void)requestFinished:(ASIHTTPRequest*)request;
//-(void)requestFailed:(ASIHTTPRequest*)request;

@end